#!/usr/bin/perl
use strict;
use modules::encode;
package csinvite;

sub csinvite {
    my ($dbh,$remote,$input,$csnum) = (shift,shift,shift,shift);
    my $sth;my $auth;
    if ($$input[4] eq "") {
	print $remote "$csnum O $$input[0] :Syntax :INVITE <#channel>\n";
    }
    else {
	$sth=$dbh->prepare("SELECT auth FROM ninfo WHERE num = '$$input[0]' AND code = '".encode::encode($$input[0])."';");
	$sth->execute;
	if (!($auth=$sth->fetchrow_array)) {
	    print $remote "$csnum O $$input[0] :You have not identified yourself with nickserv.\n";
	}
	else {
	    $sth=$dbh->prepare("SELECT level FROM users WHERE rnick = '$auth' AND channel = '$$input[4]' AND level > 50");
	    $sth->execute;
	    if (!$sth->fetchrow_array) {
		print $remote "$csnum O $$input[0] :Access denied.\n";
	    }
	    else {
		$sth=$dbh->prepare("SELECT nick FROM ninfo WHERE num = '$$input[0]' AND code = '".encode::encode($$input[0])."';");
		$sth->execute;
		my $tmp =$sth->fetchrow_array;
		print $remote "$csnum I $tmp $$input[4]\n";
		print $remote "$csnum O $$input[0] :Ok..\n";
	    }
	}
    }
}
1;
